import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;

public class HashSetTest {

    public static void main(String[] args) {
        HashSet<Integer> hashSet = new HashSet<>(Arrays.asList(3, 2, 3, 4,7,1));

        // 检查是否为空
        System.out.println(hashSet.isEmpty());

        // 输出集合大小
        System.out.println(hashSet.size());

        if (hashSet.contains(3)){
            System.out.println("存在");
        }else {
            System.out.println("不存在");
        }
        // 插入新元素
        hashSet.add(10);

        // 遍历
        printHashSet01(hashSet);

        // 遍历
        printHashSet02(hashSet);
    }

    private static void printHashSet02(HashSet<Integer> hashSet) {
        System.out.println();
        System.out.println("-------------------------");
        Iterator<Integer> iterator = hashSet.iterator();
        while (iterator.hasNext()){
            System.out.print(iterator.next()+" ");
        }
    }

    private static void printHashSet01(HashSet<Integer> hashSet) {
        for (Integer num : hashSet) {
            System.out.print(num+" ");
        }


    }


}
